﻿namespace WebUI.Controls
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Collections.Generic;
    using IGIS.Core;
    using System.Linq;
    public class EditFooterTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Button lbUpdate = new Button {
                Text = "אישור",
                OnClientClick = "return confirm('האם ברצונך לשמור את השינויים?');",
                CausesValidation = false,
                CommandName = "Update"
            };
            
            container.Controls.Add(lbUpdate);
            container.Controls.Add(new LiteralControl("&nbsp;"));
            Button lbCancel = new Button {
                Text = "ביטול",
                CausesValidation = false,
                CommandName = "Cancel"
            };
           
            container.Controls.Add(lbCancel);
        }
    }

    public class ViewFooterTemplate : ITemplate
    {
        // Methods
        public void InstantiateIn(Control container)
    {
        Button lbEdit= new Button {
            Text = "עדכון",
            CausesValidation = false,
            CommandName = "Edit"
        };
       
        container.Controls.Add(lbEdit);
    }
    }

    public class ViewPropertyFieldTemplate : ITemplate
    {
        // Fields
        private List<Control> c;

        // Methods
        public ViewPropertyFieldTemplate(FeatureProperty p)
    {
        Label lbl;
        this.c = new List<Control>();
        if (p.PropertyType == 1)
        {
            CheckBox cb = new CheckBox {
                ID = p.Name,
                Checked = bool.Parse(p.Value.ToString()),
                Enabled = false
            };
           
            this.c.Add(cb);
             lbl = new Label {
                Text = cb.Checked ? "(כן)" : "(לא)",
                ID = string.Format("lbl_{0}", p.Name)
            };
           
            this.c.Add(lbl);
        }
        else
        {
            lbl = new Label();
            if (p.DisplayedValue != null)
            {
                if ((p.LookUpValues != null) && (p.LookUpValues.Count > 0))
                {
                    IEnumerable<KeyValuePair<int, string>> vals = from x in p.LookUpValues
                        where x.Key == Convert.ToInt32(p.Value)
                        select x;
                    foreach (Label lblTxt in from v in vals select new Label { Text = v.Value, ID = p.Name + "_txt" })
                    {
                        lbl.Visible = false;
                        this.c.Add(lblTxt);
                        break;
                    }
                }
                lbl.Text = p.DisplayedValue;
            }
            lbl.ID = p.Name;
            this.c.Add(lbl);
        }
    }

        public void InstantiateIn(Control container)
        {
            foreach (Control ctrl in this.c)
            {
                container.Controls.Add(ctrl);
            }
        }
    }




}

